package com.wangyi.view;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.wangyi.activity.R;
import com.wangyi.sdk.Group;
import com.wangyi.sdk.User;

public class GroupAdapter extends BaseAdapter {
	private final Context context;
	private final List<?> groupList;

	public GroupAdapter(Context context, List<?> groupList) {
		super();
		this.context = context;
		this.groupList = groupList;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return groupList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		TextView groupText;
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(R.layout.groupadapter, null);
			groupText = (TextView) convertView.findViewById(R.id.groupname_tv);
		} else {
			groupText = (TextView) convertView.findViewById(R.id.groupname_tv);
		}
		if (groupList.get(position) instanceof User) {
			groupText.setText(((User) groupList.get(position)).getName());
		} else if (groupList.get(position) instanceof Group) {
			groupText.setText(((Group) groupList.get(position)).getName());
		}
		return convertView;
	}

}
